/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.managed;

import beans.ejb.FantasyleagueFacade;
import beans.ejb.FantasyteamFacade;
import beans.ejb.FantasyuserFacade;
import entities.Fantasyleague;
import entities.Fantasyteam;
import entities.Fantasyuser;
import java.util.Map;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author nujwoo
 */
@ManagedBean
@RequestScoped
public class OwnerBean {

        
    private String id1;
    private String id2;
    private String id3;
    private String id4;
    private String id5;
    private String id6;
    private String id7;
    private String id8;
    
    @EJB
    private FantasyuserFacade userFacade;
    @EJB
    private FantasyteamFacade teamFacade;
    @EJB
    private FantasyleagueFacade leagueFacade;
     
    
    public OwnerBean(){System.err.println("C");}
    
    public void inviteTeam(int n)
    {
        System.err.println("1");
        System.err.println("id1 : " + id1);
        System.err.println("id2 : " + id2);
        System.err.println("id3 : " + id3);
        System.err.println("id4 : " + id4);
        System.err.println("id5 : " + id5);
        System.err.println("id6 : " + id6);
        System.err.println("id7 : " + id7);
        System.err.println("id8 : " + id8);
        System.err.println("2");
        
        
        
        Fantasyuser fu = null;
        
        if(id1 != null)
            fu = userFacade.getUserByEmail(id1);
        else if(id2 != null)
            fu = userFacade.getUserByEmail(id2);
        else if(id3 != null)
            fu = userFacade.getUserByEmail(id3);
        else if(id4 != null)
            fu = userFacade.getUserByEmail(id4);
        else if(id5 != null)
            fu = userFacade.getUserByEmail(id5);
        else if(id6 != null)
            fu = userFacade.getUserByEmail(id6);
        else if(id7 != null)
            fu = userFacade.getUserByEmail(id7);
        else if(id8 != null)
            fu = userFacade.getUserByEmail(id8);
        
        
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        AccountBean b = (AccountBean)request.getSession().getAttribute("accountBean");
        
        Fantasyleague fl = b.getCurrentLeague();
        
        
        Fantasyteam ft = new Fantasyteam();
        ft.setLeagueId(fl);
        ft.setUserId(fu);
        ft.setCurrentLose(0);
        ft.setCurrentWin(0);
        ft.setCurrentWithdraw(0);
        System.err.println("Get Name");
        ft.setName(b.getLoginName());
       
        teamFacade.create(ft);
        
        b.setCurrentLeagueMember();
        
        makeTeamsEmpty();
        
    }
    
         
     public void makeTeamsEmpty()
     {
         id1 = "";
         id2 = "";
         id3 = "";
         id4 = "";
         id5 = "";
         id6 = "";
         id7 = "";
         id8 = "";
     }
    
    
    public void banTeam(int n)
    {
        
        
        FacesContext context = FacesContext.getCurrentInstance();
        Map <String, String> m = context.getExternalContext().getRequestParameterMap();
        
        String action = m.get("action");
          
        System.err.println(action);
          
         
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        AccountBean b = (AccountBean)request.getSession().getAttribute("accountBean");
        
        
        
        //Enumeration ll = request.getParameterNames();
        
        //Enumeration lll = request.getAttributeNames();
        
        Fantasyleague fl = b.getCurrentLeague();
        Fantasyuser fu = (Fantasyuser) userFacade.getUserById(action);
        
       // Fantasyteam ft = (Fantasyteam)teamFacade.getTeamId(fl, fu);
        
        
        Fantasyteam ft = (Fantasyteam)teamFacade.getTeamById(action);
        
        teamFacade.remove(ft);
        
        b.setCurrentLeagueMember();
        
        
    }

    String action;
 

    public String getId1() {
        return id1;
    }

    public void setId1(String id1) {
        this.id1 = id1;
    }

    public String getId2() {
        return id2;
    }

    public void setId2(String id2) {
        this.id2 = id2;
    }

    public String getId3() {
        return id3;
    }

    public void setId3(String id3) {
        this.id3 = id3;
    }

    public String getId4() {
        return id4;
    }

    public void setId4(String id4) {
        this.id4 = id4;
    }

    public String getId5() {
        return id5;
    }

    public void setId5(String id5) {
        this.id5 = id5;
    }

    public String getId6() {
        return id6;
    }

    public void setId6(String id6) {
        this.id6 = id6;
    }

    public String getId7() {
        return id7;
    }

    public void setId7(String id7) {
        this.id7 = id7;
    }

    public String getId8() {
        return id8;
    }

    public void setId8(String id8) {
        this.id8 = id8;
    }
    
    
    
}